<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="false">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row :gutter="48">
          <a-col :span="24">
            <a-form-model-item label="故障" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="fault">
              <a-input :disabled=formDisabled v-model="model.fault" placeholder="请输入故障"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="维修项目" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="maintenanceItems">
              <a-input :disabled=formDisabled v-model="model.maintenanceItems" placeholder="请输入维修项目"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="维修金额（元）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="maintenanceMoney">
              <a-input :disabled=formDisabled v-model="model.maintenanceMoney" placeholder="请输入维修金额（元）"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="remark">
              <a-textarea :disabled="formDisabled" :max-length="500" v-model="model.remark" rows="4" placeholder="请输入备注"/>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  // import { httpAction, getAction } from '@/api/manage'
  // import { validateDuplicateValue } from '@/utils/util'
  export default {
    name: 'ErpCarMaintenanceDetailsForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        flag: false,
        model:{
         },
        labelCol: {
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 24 },
        },
        confirmLoading: false,
        validatorRules: {
          maintenanceItems: [
            { required: true, message: '请输入维修项目!',whitespace:true},
          ],
          maintenanceMoney: [
            { required: true, message: '请输入维修金额（元）!',whitespace:true},
            { pattern: /^(([1-9][0-9]*)|([0]\.\d{0,2}|[1-9][0-9]*\.\d{0,2}))$/, message: '请输入正确维修金额（元）!' },
          ],
        },
        url: {
          add: "/api/erp/erpcarmaintenancedetails/erpCarMaintenanceDetails/add",
          edit: "/api/erp/erpcarmaintenancedetails/erpCarMaintenanceDetails/edit",
          queryById: "/api/erp/erpcarmaintenancedetails/erpCarMaintenanceDetails/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.$refs["form"].clearValidate();
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.$emit('ok', this.model, this.flag);
          }

        })
      },
    }
  }
</script>
